// MsgQ.h: interface for the CMsgQ class.
//
//////////////////////////////////////////////////////////////////////


#pragma once

#include "define.h"

#include "Queue.h"
#include "Buff.h"

class CMsgQ  
{
	enum
	{
		DEF_DEFAULT_SIZE = 1024,
	};

public:
	CMsgQ() {}
	virtual ~CMsgQ() {}

	bool isEmpty()
	{
		if( m_que.isEmpty() && !m_buff.getSize() )
			return true;

		return false;
	}

	void push( char* msg, size_t size )
	{
		if( DEF_DEFAULT_SIZE <= (m_buff.getSize()+size) )
		{
			m_que.push( m_buff );
			m_buff.clear();

			return;
		}

		m_buff.put( msg, size );		
	}

	int pop( CBuff& buff )
	{
		if( m_buff.getSize() )
		{
			m_que.push( m_buff );
			m_buff.clear();
		}

		if( !m_que.isEmpty() )
			return m_que.pop( buff );

		return 0;
	}	

private:
	CQueue<CBuff>	m_que;
	CBuff			m_buff;
};
